Imports System.ComponentModel


Namespace myBookmarks.Core


    Public Class Bookmark
        Implements IDataErrorInfo


        Public Sub New()
            _labels = New List(Of Label)
        End Sub
        Private _BookmarkId As Integer
        Public Property BookmarkId() As Integer
            Get
                Return _BookmarkId
            End Get

            Set(ByVal value As Integer)
                _BookmarkId = value
            End Set
        End Property
        Private _Name As String
        Public Property Name() As String
            Get
                Return _Name
            End Get

            Set(ByVal value As String)
                _Name = value
            End Set
        End Property
        Private _Location As String

        Public Property Location() As String
            Get
                Return _Location
            End Get

            Set(ByVal value As String)
                _Location = value
            End Set
        End Property



        Private _Notes As String
        Public Property Notes() As String
            Get
                Return _Notes
            End Get

            Set(ByVal value As String)
                _Notes = value
            End Set
        End Property


        Private _UserName As String
        Public Property UserName() As String
            Get
                Return _UserName
            End Get

            Set(ByVal value As String)
                _UserName = value
            End Set
        End Property



        Private _CreatedDate As DateTime
        Public Property CreatedDate() As DateTime
            Get
                Return _CreatedDate
            End Get

            Set(ByVal value As DateTime)
                _CreatedDate = value
            End Set
        End Property
        Private _LastUpdated As DateTime
        Public Property LastUpdated() As DateTime
            Get
                Return _LastUpdated
            End Get

            Set(ByVal value As DateTime)
                _LastUpdated = value
            End Set
        End Property

        Private _labels As List(Of Label)
        Public Property Labels() As List(Of Label)
            Get
                Return _labels
            End Get
            Set(ByVal value As List(Of Label))
                _labels = value
            End Set
        End Property

        Public Sub AddLabel(ByVal labelname As String)
            Dim LabelList As New List(Of Label)
            Dim enteredLabels As String() = labelname.Split(New Char() {","}, StringSplitOptions.RemoveEmptyEntries)
            For Each s As String In enteredLabels
                LabelList.Add(New Label With {.LabelName = s.Trim, .UserName = UserName})
            Next
            Labels = LabelList
        End Sub
        Private _errors As New Dictionary(Of String, String)()
        Public ReadOnly Property [Error]() As String Implements IDataErrorInfo.Error
            Get
                Return String.Empty
            End Get
        End Property

        Default Public ReadOnly Property Item(ByVal columnName As String) As String Implements IDataErrorInfo.Item
            Get
                Dim results As String = Nothing

                Select Case columnName
                    Case "Location"
                        If String.IsNullOrEmpty(Location) Then
                            _errors.Add("Location", "Please Enter a Valid Location.")
                        End If
                        Exit Select
                End Select
                If _errors.ContainsKey(columnName) Then
                    Return _errors(columnName)
                End If
                Return String.Empty
            End Get
        End Property
    End Class

End Namespace